package com.mate.cloud.oauth2.service.impl;

import com.mate.cloud.oauth2.domain.MateUser;
import com.mate.cloud.oauth2.service.UserDetailService;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户详细信息
 *
 * @author: MI
 * @email: 448341911@qq.com
 * @createTime: 2024/6/11 18:29
 * @updateUser: MI
 * @updateTime: 2024/6/11 18:29
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Service
public class MateUserDetailServiceImpl implements UserDetailService {
    @Resource
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MateUser user = new MateUser();
        user.setUserName(username);
        user.setPassword(this.passwordEncoder.encode("123456"));
        return new User(username, user.getPassword(), user.isEnabled(),
                user.isAccountNonExpired(), user.isCredentialsNonExpired(),
                user.isAccountNonLocked(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
